<template>
  <!--语言能力-->
  <view>
    <myHead
      :title="title"
      :right="true"
      text_right="保存"
      @clickRight="clickRight"
    ></myHead>
    <view class="conten">
      <u-picker
        :show="show1"
        title="语种"
        :columns="list1"
        closeOnClickOverlay
        @close="show1 = false"
        @cancel="show1 = false"
        @confirm="languageChange"
      ></u-picker>

      <view class="li-box fl-lr-c" @click="languageClick">
        <view class="name">语种</view>
        <view class="fl-t">
          <view class="content">
            {{ language || "请选择" }}
          </view>
          <u-icon name="arrow-right"></u-icon>
        </view>
      </view>

      <u-picker
        :show="show2"
        title="听说能力"
        :columns="list2"
        v-if="list2"
        closeOnClickOverlay
        @close="show2 = false"
        @cancel="show2 = false"
        @confirm="languageChange2"
      ></u-picker>

      <view class="li-box fl-lr-c" @click="show2 = true">
        <view class="name">听写能力</view>
        <view class="fl-t">
          <view class="content">
            {{ lsit2text || "请选择" }}
          </view>
          <u-icon name="arrow-right"></u-icon>
        </view>
      </view>

      <u-picker
        :show="show3"
        title="读写能力"
        :columns="list3"
        v-if="list3"
        closeOnClickOverlay
        @close="show3 = false"
        @cancel="show3 = false"
        @confirm="languageChange3"
      ></u-picker>

      <view class="li-box fl-lr-c" @click="show3 = true">
        <view class="name">读写能力</view>
        <view class="fl-t">
          <view class="content">
            {{ lsit3text || "请选择" }}
          </view>
          <u-icon name="arrow-right"></u-icon>
        </view>
      </view>
    </view>
    <bottomBut @bottomBut="bottomBut" v-if="type == 2"></bottomBut>
  </view>
</template>

<script>
import myHead from "@/pages/component/baseHead.vue";
import bottomBut from "@/pages/component/bottomBut.vue";
export default {
  data() {
    return {
      title: "语言能力",
      type: 0,
      show1: false,
      show2: false,
      show3: false,
      list3: [],
      list2: [],
      list1: [],
      language: "",
      hear: "", //听
      read: "", //读
      // 当前id
      Id: 0,
      // 父id
      fuid: 0,
      resumeList: [], //查询数据库语言能力的数据
    };
  },
  //子组件
  components: {
    myHead,
    bottomBut,
  },

  onLoad(o) {
    this.type = o.type;
    this.fuid = o.fuid;
    if (this.type == 2) {
      o = JSON.parse(o.data);
      console.log(o);
      this.Id = o.Id;
      this.language = o.Lang;
      this.hear = o.LsLevel;
      this.read = o.RwLevel;
    }

    this.removalLang();
  },
  created() {
    this.xialadata();
  },
  computed: {
    lsit2text() {
      let arr = [];
      if (this.list2.length > 0) {
        arr = this.list2[0].filter((res) => {
          return this.hear == res.value;
        });
      }
      if (arr.length == 0) {
        return "";
      } else {
        return arr[0].text || " ";
      }
    },

    lsit3text() {
      let arr = [];
      if (this.list3.length > 0) {
        arr = this.list3[0].filter((item) => {
          return item.value == this.read;
        });
      }
      if (arr.length == 0) {
        return "";
      } else {
        return arr[0].text || " ";
      }
    },
  },
  // 计算方法
  methods: {
    //去重  调用my接口
    removalLang() {
      this.$http.huirc.resumemy().then((res) => {
        if (res.Success) {
          res = res.Result;
          this.mylistdata = res;
          console.log(res);
          //处理数据
          this.resumeList = res.LangSkills; //语言能力
          // console.log(this.resumeList);
        }
      });
      this.$http.dic.DataSelector(392893628588165).then((res) => {
        if (res.Success) {
          console.log(res.Result);
          this.list1 = this.xialist(res.Result);
        }
      });
    },
    // 去重
    DuplicateRemoval() {
      this.resumeList.forEach((itt, ind) => {
        console.log(itt);
        this.list1[0].forEach((item, index) => {
          if (itt.Lang == item.text) {
            this.list1[0].splice(index, 1);
          }
        });
      });
      console.log("this.list1", this.list1);
    },
    // 点击语种选择
    languageClick() {
      this.show1 = true;
      this.DuplicateRemoval();
    },
    xialadata() {
      this.$http.dic.DataSelector(385827670917253).then((res) => {
        if (res.Success) {
          // console.log(res.Result);
          this.list2 = this.xialist(res.Result);
          // console.log(this.list2);
        }
      });
      this.$http.dic.DataSelector(385827403714693).then((res) => {
        if (res.Success) {
          // console.log(res.Result);
          this.list3 = this.xialist(res.Result);
        }
      });
    },
    xialist(arr) {
      let drr = [];
      arr.forEach((res) => {
        let obj = {
          text: res.FullName,
          value: res.EnCode,
        };
        drr.push(obj);
      });
      return [drr];
    },

    languageChange(e) {
      console.log(e);
      this.language = e.value[0].text;
      this.show1 = false;
    },
    languageChange2(e) {
      this.hear = e.value[0].value;
      this.show2 = false;
    },
    languageChange3(e) {
      console.log(e);
      this.read = e.value[0].value;
      this.show3 = false;
    },
    bottomBut() {
      let that = this;
      console.log("删除");
      uni.showModal({
        title: "删除提示",
        content: "确认要删除这条数据",
        success: function (res) {
          if (res.confirm) {
            let data = {
              Id: that.Id,
            };

            that.$http.huirc.resumelangskilldel(data).then((res) => {
              if (res.Success) {
                that.$util.toast("删除成功");
                setTimeout(() => {
                  uni.navigateBack();
                }, 1600);
              }
            });
          }
        },
      });
    },
    clickRight() {
      if (!this.language) {
        this.$util.toast("请选择语种");
        return;
      }
      if (!this.hear) {
        this.$util.toast("请选择听写能力");
        return;
      }

      if (!this.read) {
        this.$util.toast("请选择读写能力");
        return;
      }

      if (this.type == 2) {
        //编辑修改
        let data = {
          Id: this.Id,
          ResumeId: this.fuid,
          Lang: this.language,
          RwLevel: this.read,
          LsLevel: this.hear,
        };
        this.$http.huirc.resumelangskillup(data).then((res) => {
          if (res.Success) {
            this.$util.toast("保存成功");
            setTimeout(() => {
              uni.navigateBack();
            }, 1000);
          }
        });
      } else {
        let data = {
          ResumeId: this.fuid,
          Lang: this.language,
          RwLevel: this.read,
          LsLevel: this.hear,
        };
        this.$http.huirc.resumelangskillcr(data).then((res) => {
          if (res.Success) {
            this.$util.toast("保存成功");
            setTimeout(() => {
              uni.navigateBack();
            }, 1000);
          }
        });
      }
    },
  },
};
</script>


<style lang="scss" scoped>
.li-box {
  background-color: #fff;
  .name {
    font-size: 30rpx;
    font-family: PingFang SC;
    font-weight: bold;
    color: #000000;
    flex-shrink: 0;
  }

  .logo {
    width: 106rpx;
    height: 106rpx;
    border-radius: 50%;
  }

  .input_pal,
  input,
  .content {
    font-size: 30rpx;
    font-family: PingFang SC;
    font-weight: 500;
    color: #999999;
    text-align: end;
  }

  .radio-box {
    margin-left: 50rpx;

    .radio-text {
      font-size: 30rpx;
      font-family: PingFang SC;
      font-weight: 500;
      color: #999999;
      padding-left: 20rpx;
    }
  }

  .tui-textarea {
    flex: 1;
  }
}
</style>
